package com.cat.greedyAlgorithm;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-operations-to-reduce-an-integer-to-0/?envType=problem-list-v2&envId=rFbd9B5V
 * @create 2025/10/8 21:55
 * @since JDK17
 */

public class Solution61 {
    public int minOperations(int n) {
        String s = Integer.toBinaryString(n);
        int ans = 0, m = s.length();
        for (int i = 0; i < m; i++) {
            int start = i;
            while (i < m && s.charAt(i) == '1') {
                i++;
            }
            ans += (i - start > 2) ? 2 : i - start;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Integer.toBinaryString(10));
        System.out.println(Integer.toBinaryString(-10));

    }
}
